package com.lin.reggie.controller;

import com.lin.reggie.common.R;
import com.lin.reggie.dto.SetmealDto;
import com.lin.reggie.entity.Page;
import com.lin.reggie.entity.Setmeal;
import com.lin.reggie.service.SetmealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/setmeal")
@Slf4j
@Api(tags = "套餐管理接口")
public class SetmealController {

    @Autowired(required = false)
    private SetmealService setmealService;

    //添加
    @ApiOperation(value = "新增套餐接口")
    @PostMapping
    public R<String>save(@RequestBody SetmealDto setmealDto, HttpSession session){
        //获取登录人
        Long employee = (Long) session.getAttribute("employee");
        //创建人
        setmealDto.setCreateUser(employee);
        setmealDto.setUpdateUser(employee);
        setmealService.save(setmealDto);
        return R.success("添加成功");
    }

    //分页查询
    @ApiOperation(value = "套餐分页查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "页码",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页记录数",required = true),
            @ApiImplicitParam(name = "name",value = "套餐名称",required = false)
    })
    @GetMapping("/page")
    public R<Page<SetmealDto>>page(Integer page,Integer pageSize,String name){
        Page<SetmealDto> pageResult = setmealService.findByPage(page, pageSize, name);
        return R.success(pageResult);
    }


    //伪删除
    @DeleteMapping
    public R<String>deleteByIds(@RequestParam List<Long>ids,HttpSession session){
        //获取操作人
        Long id = (Long) session.getAttribute("employee");
        //调用业务方法去删除
        setmealService.deleteByIds(ids,id);
        return R.success("删除套餐成功");
    }

    @GetMapping("/list")
    public R<List<Setmeal>>findSetmeal(Long categoryId,Integer status){
        List<Setmeal> setmealList = setmealService.findSetmeal(categoryId,status);
        return R.success(setmealList);
    }
    /*
    *  @GetMapping("/list")
    public R<List<DishDto>>findByDishCategoryId( Long categoryId,Integer status){
        List<DishDto> dishList = dishService.findByCategoryId(categoryId,status);
        return R.success(dishList);
    }
    *
    * */
}
